<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>

<div>
    <a href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-add'" onclick="openAllArticle()">添加</a>
    <a  href="javascript:void(0)" class="easyui-linkbutton"
        data-options="iconCls:'icon-remove'" onclick="doDelete()">批量删除</a>
    <input type="button" value="重置索引库" onclick="reset()"/>
    <input type="button" value="添加索引库" onclick="add()"/>
    <input type="text" name="text" id="textId"/>
    <a id="standardQueryBtn" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>

</div>
<table id="article"></table>
<div id="addArticle">
    <form id="articleForm" style="margin:30px" enctype="multipart/form-data" method="post">
        <table>
            <tr>
                <td>文章名字：<input name="articleName" /></td>
            </tr>
            <tr>
                <td>文章图片地址：<input name="articleImg" type="file"/></td>
            </tr>
            <tr>
                <td>文章描述：<input name="articleContent" /></td>
            </tr>
            <tr>
                <td> 上师所属：<select id="guruCategory" name="cmfzGuru.guruId"></select></td>
            </tr>
            <tr>
                <td>上传时间：<input name="articleDate" /></td>
            </tr>
        </table>
        <center>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" onClick="addArticle()">确认</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
        </center>
    </form>
</div>

<div id="updateArt">
    <form id="updateArtForm"enctype="multipart/form-data" method="post">
        <table>
            <tr>
                <input id="artid" name="articleId" />
                <td>文章名字：<input id="artName" name="articleName" /></td>
            </tr>
            <tr>
                <td>文章图片地址：<input name="articleImg" type="file"/></td>
            </tr>
            <td colspan="2"><p id="artImage"></p></td>
            <tr>
                <td>文章描述：<input id="artContent" name="articleContent" /></td>
            </tr>
            <tr>
                <td> 上师所属：<select id="guruCategory2" name="cmfzGuru.guruId"></select></td>
            </tr>
            <tr>
                <td>上传时间：<input id="artDate" name="articleDate" /></td>
            </tr>
        </table>
        <center>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" onClick="update()">确认</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
        </center>
    </form>
</div>

<div>
    <form action="" method="post">
    </form>
</div>
<script type="text/javascript">
    $(function(){
        //动态添加点击事件
        $("#standardQueryBtn").click(function () {
            var text = $("#textId").val();
            $('#article').datagrid({
                url:"${pageContext.request.contextPath}/showByLucene?text="+text,
                pagination : true,
                pageList : [ 5, 10, 15, 20 ],
                pageSize : 5,
                javaType:"JSON",
                columns:[[
                    {checkbox:true},
                    {field:'articleId',title:'文章id',width:100},
                    {field:'articleName',title:'文章名',width:100},
                    {field:'articleImage',title:'文章图片',width:100,align:'right',formatter: function (value, row, index) {
                        return "<img height='50' width='30' src='${pageContext.request.contextPath}"+value+"'/>";
                    }},
                    {field:'articleContent',title:'文章内容',width:100},
                    {title : "操作",field : "cz",formatter : function(value, row, index) {
                        return "<a href='deleteBanner?ids=" + row.bannerId + "'>删除</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='update()'>修改</a>";
                    }
                    }
                ]]
            })
        })



        $("#addArticle").dialog({
            width:600,
            height:450,
            title:"添加轮播图",
            closed:true
        });
        $("#updateArt").dialog({
            width:600,
            height:450,
            title:"修改",
            closed:true,
        });

            $('#article').datagrid({
                onDblClickRow: function(rowIndex,rowData){
                    $("#updateArt").dialog("open");
                    $("#artid").val(rowData.articleId);
                    $("#artName").val(rowData.articleName);
                    $("#artImage").html("<img src='${pageContext.request.contextPath}" + rowData.articleImage + "' width=30px height=50px />");
                    $("#artContent").val(rowData.articleContent);
                    $("#artDate").val(rowData.articleDate);
                    $.ajax({
                        url:"${pageContext.request.contextPath}/cmfzGuru/showAllGuru",
                        success:function(data){
                            for(var i=0;i<data.length;i++){
                                $("#guruCategory2").append("<option value="+data[i].guruId+">"+data[i].guruName+"</option>");
                            }
                        }
                    });
                },

                url:'${pageContext.request.contextPath}/cmfzArticle/queryAllCmfzArticle',
                pagination : true,
                pageList : [ 5, 10, 15, 20 ],
                pageSize : 5,
                javaType:"JSON",
                columns:[[
                    {checkbox:true},
                    {field:'articleId',title:'文章id',width:100},
                    {field:'articleName',title:'文章名',width:100},
                    {field:'articleImage',title:'文章图片',width:100,align:'right',formatter: function (value, row, index) {
                        return "<img height='50' width='30' src='${pageContext.request.contextPath}"+value+"'/>";
                    }},
                    {field:'articleContent',title:'文章内容',width:100},
                    {field:'guruId',title:'上师id',width:100},
                    {field:'articleDate',title:'文章时间',width:100},
                    {title : "操作",field : "cz",formatter : function(value, row, index) {
                            return "<a href='deleteBanner?ids=" + row.bannerId + "'>删除</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='update()'>修改</a>";
                        }
                    }
                ]]
            });
        }
    )
    function openAllArticle(){
        $("#addArticle").dialog("open");
        $.ajax({
            url:"${pageContext.request.contextPath}/cmfzGuru/showAllGuru",
            success:function(data){
                console.info(data)
                for(var i=0;i<data.length;i++){
                    $("#guruCategory").append("<option value="+data[i].guruId+">"+data[i].guruName+"</option>");
                }
            }
        });
    }

//    删除
    function doDelete(){
        var idd = $("#banners").datagrid("getSelections");
        if(idd.length==0){
            //提示框
            $.messager.alert('提示框',"请选择要删除的信息",'warning');
        }else{
            //提示框
            $.messager.confirm('提示框',"确定要删除吗",function(d){
                if(d){
                    //存储所有的id
                    var id = new Array();
                    for(var i=0;i<idd.length;i++){
                        id[i]=idd[i].bannerId;
                    }
                    //alert(id);
                    $.ajax({
                        url:"${pageContext.request.contextPath}/banner/deleteBanner",
                        type:"post",
                        data:"id="+id,
                        success:function(data){
                            if(data){
                                $.messager.alert('提示框',"删除成功",'info');
                                $("#prodatagrid").datagrid("reload");
                            }else{
                                $.messager.alert('提示框',"删除失败",'warning');
                            }
                        }
                    });
                }
            });
        }
    }
    //添加
    function addArticle(){
        $('#articleForm').form('submit', {
            url:"${pageContext.request.contextPath}/cmfzArticle/insertCmfzAlbum",
            onSubmit: function(){
                return true;
            },
            success:function(data){
                if(addArticle){
                    $.messager.alert('提示框',"添加成功",'info');
                    $("#article").datagrid("reload");
                    $("#addArticle").dialog("close");
                }else{
                    $.messager.alert('提示框',"添加失败",'warning');
                }

            }
        });
    }
    function update(){
        $("#myForm2").form("submit",{
            url:"${pageContext.request.contextPath}/banner/updateBanenr",
            success:function(data){
                if(data){
                    $.messager.alert('提示框',"修改成功",'info');
                    $("#article").datagrid("reload");
                    $("#updateBanner").dialog("close");
                }else{
                    $.messager.alert("提示框","修改失败","warning");
                }
            }
        });
    }
</script>